﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using HelloThriftspace;
using System.Threading;
namespace Thrift.Server
{
    public class HelloThriftHandler : HelloThrift.Iface
    {

        public void HelloWorld()
        {
            Console.WriteLine("hello world!");
        //    DoWork.Data.Enqueue(obj);
        }

     
    }

    public class DoWork
    {

        private static Queue<object> data = new Queue<object>();

        public static Queue<object> Data
        {
            get { return DoWork.data; }
            set { DoWork.data = value; }
        }


        private static Queue<object> sendData = new Queue<object>();

        public static Queue<object> SendData
        {
            get { return DoWork.sendData; }
            set { DoWork.sendData = value; }
        }

        public static void Start()
        {
            new Thread(() =>
            {
                Console.WriteLine("接收服务开启...");
                while (true)
                {

                    if (Data.Count > 0)
                    {
                        Do(Data.Dequeue());
                    }
                    else
                    {
                        System.Threading.Thread.Sleep(200);
                    }
                }
            }).Start();

            new Thread(() =>
            {
                Console.WriteLine("发送服务开启...");
                while (true)
                {

                    if (SendData.Count > 0)
                    {
                        Do_Send(Data.Dequeue());
                    }
                    else
                    {
                        System.Threading.Thread.Sleep(200);
                    }
                }
            }).Start();

        }


        public static void Do(object data)
        {
            //  需要回发client


            object data_send = data.ToString();
            SendData.Enqueue(data_send);
        }



        public static void Do_Send(object data)
        {

        }

    }


}
